package com.alibaba.otter.manager.web.codegen;

import com.alibaba.otter.canal.instance.manager.model.Canal;
import com.alibaba.otter.canal.instance.manager.model.CanalParameter;
import com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat;
import com.alibaba.otter.manager.biz.statistics.table.param.BehaviorHistoryInfo;
import com.alibaba.otter.manager.web.dto.*;
import com.alibaba.otter.shared.arbitrate.model.MainStemEventData;
import com.alibaba.otter.shared.arbitrate.model.PositionEventData;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRule;
import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.channel.ChannelParameter;
import com.alibaba.otter.shared.common.model.config.data.*;
import com.alibaba.otter.shared.common.model.config.node.Node;
import com.alibaba.otter.shared.common.model.config.node.NodeParameter;
import com.alibaba.otter.shared.common.model.config.parameter.SystemParameter;
import com.alibaba.otter.shared.common.model.config.pipeline.Pipeline;
import com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter;
import com.alibaba.otter.shared.common.model.config.record.LogRecord;
import com.alibaba.otter.shared.common.model.statistics.delay.DelayStat;
import com.alibaba.otter.shared.common.model.statistics.stage.ProcessStat;
import com.alibaba.otter.shared.common.model.statistics.table.TableStat;
import com.alibaba.otter.shared.common.model.statistics.throughput.ThroughputStat;
import com.alibaba.otter.shared.common.model.user.User;
import org.springframework.util.ReflectionUtils;

import java.util.*;

public class PageListCodeGenApplication {



    private Map<Class<?>,String> types = new HashMap<>();
    {
                types.put(String.class,"string");
                types.put(Date.class,"string");
                types.put(List.class,"Array");
                types.put(Set.class,"Array");
                types.put(Boolean.class,"boolean");
                types.put(boolean.class,"boolean");
                types.put(Integer.class,"number");
                types.put(Long.class,"number");
                types.put(Short.class,"number");
    }

    public static void main(String[] args) {
        PageListCodeGenApplication pages = new PageListCodeGenApplication();
        List<Class<?>> types = List.of(
                UserDTO.class
        );
        for (Class<?> type : types) {
            System.out.println(pages.genTypeCode(type));
        }
    }




    private String genTypeCode(Class<?> channel){

        StringBuilder typesb = new StringBuilder();

        typesb.append("type ").append(channel.getSimpleName()).append("= {");

        ReflectionUtils.doWithFields(channel,f -> {
            if (f.getName().equals("serialVersionUID")){
                return;
            }
            typesb.append(f.getName()).append("?: ").append(types.getOrDefault(f.getType(),"any")).append(";");
        });
        typesb.append("};");
        return typesb.toString();

    }

}
